Page({
  data: {
    point: '', // 小区信息
    building: '', // 楼栋信息
    rooms: [], // 随机产生的房间号
  },
  onLoad({ point, building }) {
    this.fakeData(point, building)
  },
  // 1. 造数据
  fakeData(point, building) {
    // 1.1 随机产生房间的数量 5-8
    const size = Math.floor(Math.random() * 4) + 5
    // 1.2 随机产生房间号  102 2002
    const rooms = []
    for (let i = 0; i < size; i++) {
      // 1.2.1 随机产生楼层 1-20
      const floor = Math.floor(Math.random() * 20) + 1
      // 1.2.2 随机产生房间号 1-4
      const no = Math.floor(Math.random() * 4) + 1
      // 1.2.3 组合房间号放入数组
      const room = [floor, '0', no].join('')
      if (rooms.includes(room)) continue // 去重处理
      rooms.push(room)
    }
    // 1.3 更新数据
    this.setData({
      rooms,
      point,
      building,
    })
  },
  // 2. 跳转去表单页面
  goForm(ev) {
    const { point, building } = this.data
    wx.navigateTo({
      url: `/house_pkg/pages/form/index?point=${point}&building=${building}&room=${ev.mark.room}`,
    })
  },
})
